package com.photoeditor.demo.ui.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PaintFlagsDrawFilter;
import android.util.AttributeSet;
import android.view.View;

import com.common.base.ComponentContext;
import com.photoeditor.R;

import static com.android.graffiti.ColorRadioButton.STROKE_PAINT_WIDTH;

/**
 * Created by winn on 17/10/19.
 */

public class ArcBgView extends View {
    private static Paint sStrokePaint;

    public ArcBgView(Context context) {
        super(context);
    }

    public ArcBgView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ArcBgView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onAttachedToWindow() {
        setLayerType(View.LAYER_TYPE_HARDWARE, null);
        super.onAttachedToWindow();
        if (sStrokePaint == null) {
            sStrokePaint = new Paint();
            sStrokePaint.setColor(ComponentContext.getContext().getResources().getColor(R.color.accent_color));
            sStrokePaint.setStrokeJoin(Paint.Join.ROUND);
            sStrokePaint.setStrokeWidth(STROKE_PAINT_WIDTH);
            sStrokePaint.setStyle(Paint.Style.STROKE);
            sStrokePaint.setAntiAlias(true);
        }
    }

    @Override
    public void draw(Canvas canvas) {
        canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
        canvas.drawCircle(getWidth() / 2, getHeight() / 2,
                getWidth() / 2 - STROKE_PAINT_WIDTH / 2 - 0.5f, sStrokePaint);
    }
}
